package cn.sw.common.database.architecture.controller;

import cn.sw.common.database.architecture.service.BaseService;
import cn.sw.common.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @param <T> 实体类
 * @param <F> 表单类
 * @param <Q> 条件类
 * @Description: 基础控制器
 * @Author: 张众森
 * @Date: 2025/5/10
 */
public class BaseController<T, F, Q, V> {
    //    采用了spring扩展，自动注入，不用这个注入 忽略该警告
    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    protected BaseService<T, F, Q, V> baseService;

    // 根据id查询
    @GetMapping("/RById/{id}")
    public HttpResponse<?> RById(@PathVariable("id") String id) {
        return baseService.RById(id);
    }

    // 根据id列表查询
    @PostMapping("/RByIds")
    public HttpResponse<?> RByIds(@RequestBody List<String> idList) {
        return baseService.RByIds(idList);
    }

    // 根据查询条件查询
    @PostMapping("/R")
    public HttpResponse<?> R(@RequestBody Q query) {
        return baseService.R(query);
    }

    // 分页查询
    @PostMapping("/P")
    public HttpResponse<?> P(@RequestBody Q query) {
        return baseService.P(query);
    }


    // 新增
    @PostMapping("/C")
    public HttpResponse<?> C(@RequestBody F form) {
        return baseService.C(form);
    }

    // 批量新增
    @PostMapping("/CBatch")
    HttpResponse<?> CBatch(@RequestBody List<F> formList) {
        return baseService.CBatch(formList);
    }

    // 根据id更新
    @PostMapping("/UById")
    HttpResponse<?> UById(@RequestBody F form) {
        return baseService.UById(form);
    }

    // 根据id批量更新
    @PostMapping("/UBatchById")
    HttpResponse<?> UBatchById(@RequestBody List<F> formList) {
        return baseService.UBatchById(formList);
    }

    // 新增或更新
    @PostMapping("/COrU")
    HttpResponse<?> COrU(F form) {
        return baseService.COrU(form);
    }

    // 批量新增或更新
    @PostMapping("/COrUBatch")
    HttpResponse<?> COrUBatch(@RequestBody List<F> formList) {
        return baseService.COrUBatch(formList);
    }

    // 根据id删除
    @GetMapping("/DById/{id}")
    HttpResponse<?> DById(@PathVariable("id") String id) {
        return baseService.DById(id);
    }

    // 根据id列表删除
    @PostMapping("/DByIds")
    HttpResponse<?> DByIds(@RequestBody List<String> idList) {
        return baseService.DByIds(idList);
    }
}